<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Crud_controller extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		$this->load->database();
		$this->load->helper('url');
		
		$this->load->library('grocery_CRUD');	
	}
	
	function _example_output($output = null)
	{
		$this->load->view('/admin_view/crud_view',$output);	
	}
	
	function index()
	{
		$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
	}	
	
    function article_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('article');
			$crud->set_subject('Article');
			$crud->required_fields('ID');
			$crud->columns('ID','NAME','CONTENT','CREAT_DATE','AUTHOR','TYPE_ID','TYPE_NAME');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
	function jskull_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('jskull');
			$crud->set_subject('School');
			$crud->required_fields('ID');
			$crud->columns('ID','NAME','LINK','IMG','DESCRIPTION');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
                
        function lecture_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('lecture');
			$crud->set_subject('Lecture');
			$crud->required_fields('ID');
			$crud->columns('ID','NAME','COURSE_ID','LECTURER','CREATE_DATE','TYPE_FILE','PATH','LECTURE_ORDER');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
        function question_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('question');
			$crud->set_subject('Question');
			$crud->required_fields('ID');
			$crud->columns('ID','CONTENT','ANS_1','ANS_2','ANS_3','ANS_4','ANS_QUANT','CORRECT_ANS','TIME');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
        function slide_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('slide');
			$crud->set_subject('Slide');
			$crud->required_fields('ID');
			$crud->columns('ID','VIDEO_ID','PATH','CREATER','CREATE_DATE','TYPEFILE');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
        function test_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('test');
			$crud->set_subject('Test');
			$crud->required_fields('ID');
			$crud->columns('ID','CONTENT','QUANTITY_QUESTION','QUES_1','QUES_2','QUES_3','QUES_4','TIME');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
        function user_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('user');
			$crud->set_subject('User');
			$crud->required_fields('ID');
			$crud->columns('ID','NAME','FULLNAME','EMAIL','STATUS','PASSWORD','COURSE_ID','GENDER','YEAR_OF_BIRTH','CREATE_DATE');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
        
        function video_fragment_management()
	{
		try{
			$crud = new grocery_CRUD();

			$crud->set_theme('datatables');
			$crud->set_table('user');
			$crud->set_subject('User');
			$crud->required_fields('ID');
			$crud->columns('ID','VIDEO_NAME','VIDEO_TYPE','COURSE_ID','LECTURER','CREATE_DATE','SIZE','CODEC','RUNTIME','LECTURE_ID','VIDEO_ORDER','LECTURE_ORDER','PATH','SLIDE_ID','VIEW');
			
			$output = $crud->render();
			
			$this->_example_output($output);
			
		}catch(Exception $e){
			show_error($e->getMessage().' --- '.$e->getTraceAsString());
		}
	}
	
}